package com.gs.zsmanage.service.impl;

import com.gs.zsmanage.dao.UserDepartmentMapper;
import com.gs.zsmanage.entity.Department;
import com.gs.zsmanage.entity.Unit;
import com.gs.zsmanage.entity.User;
import com.gs.zsmanage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDepartmentMapper mapper;

    @Override
    public void addUser(User user) {
        mapper.addUser(user);
    }

    @Override
    public void updateUser(User user) {
        mapper.updateUser(user);
    }

    @Override
    public void deleteUser(Integer id) {
        mapper.deleteUser(id);
    }

    @Override
    public User getUserByPhone(String phone) {
        return mapper.queryUserByPhone(phone);
    }

    @Override
    public List<User> getAllUsers() {
        return mapper.listAllUsers();
    }

    @Override
    public List<User> getUsersByDepartment(String department) {
        return mapper.listUsersByDepartment(department);
    }

    @Override
    public List<User> searchUsers(String name) {
        return mapper.searchUser(name);
    }

    @Override
    public void addDepartment(Department department) {
        mapper.addDepartment(department);
        mapper.addDepartmentAndStationType(department.getName(), "区域自动站");
        mapper.addDepartmentAndStationType(department.getName(), "浮标站");
        mapper.addDepartmentAndStationType(department.getName(), "部门共享站");
        mapper.addDepartmentAndStationType(department.getName(), "大桥自动站");
        mapper.addDepartmentAndStationType(department.getName(), "水文站");
    }

    @Override
    public void updateDepartment(Department department) {
        mapper.updateDepartment(department);
    }

    @Override
    public void deleteDepartment(Integer id) {
        mapper.deleteDepartment(id);

        mapper.deleteDepartmentAndStationType(id);
    }

    @Override
    public List<Department> getAllDepartments() {
        return mapper.listAllDepartments();
    }

    @Override
    public Unit getUnitByNick(String nick) {
        return mapper.queryUnitByNick(nick);
    }
}
